//package com.mycompany.rocketmq.consumer;
//
//import java.util.List;
//
//import org.apache.commons.lang3.SerializationUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer;
//import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
//import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import com.alibaba.rocketmq.client.exception.MQClientException;
//import com.alibaba.rocketmq.common.consumer.ConsumeFromWhere;
//import com.alibaba.rocketmq.common.message.MessageExt;
//import com.alibaba.rocketmq.common.protocol.heartbeat.MessageModel;
//import com.mycompany.rocketmq.producer.Myproducer;
//import com.mycompany.user.entity.User;
//
//public class Myconsumer {
//	private final Logger logger = LoggerFactory.getLogger(Myproducer.class);
//
//	private DefaultMQPushConsumer defaultMQPushConsumer;
//	private String consumerGroup;
//	private String namesrvAddr;
//
//	/**init-method
//	 * */
//	public void init() throws InterruptedException,MQClientException{
//		/*启动日志*/
//		logger.info("defaultMQPushConsumer init");
//		logger.info("consumerGroup:"+consumerGroup);
//		logger.info("namesrvAddr:"+namesrvAddr);
//
//		/*defaultMQPushConsumer全局唯一 ConsumerGroupName应用指定*/
//		defaultMQPushConsumer = new DefaultMQPushConsumer();
//		defaultMQPushConsumer.setNamesrvAddr(namesrvAddr);
//		defaultMQPushConsumer.setConsumerGroup(consumerGroup);
//		defaultMQPushConsumer.setInstanceName(String.valueOf(System.currentTimeMillis()));
//
//		/*指定订阅内容*/
//		defaultMQPushConsumer.subscribe("TopicTest","TagB");
//		/*单队列并行消费允许的最大跨度*/
//		defaultMQPushConsumer.setConsumeConcurrentlyMaxSpan(20);
//
//		/*设置第一次启动,从头部还是尾部消费;非第一次启动,从上次消费的位置继续消费*/
//		defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//
//		/*设置为集群消费*/
//		defaultMQPushConsumer.setMessageModel(MessageModel.CLUSTERING);
//		defaultMQPushConsumer.registerMessageListener(new MessageListenerConcurrently() {
//
//			/*可以通过设置consumerMessageBatchMaxSize参数来批量接收消息*/
//			@Override
//			public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
//					ConsumeConcurrentlyContext context) {
//				 for(MessageExt ext:msgs){
//	                System.out.println("reveive:"+(User)SerializationUtils.deserialize(ext.getBody()));
//	            }
//				return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//			}
//		});
//		/*Consumer对象在使用之前必须要调用start初始化，初始化一次即可*/
//		defaultMQPushConsumer.start();
//		logger.info("defaultMQPushConsumer start success!");
//	}
//
//	/**destroy-method
//	 * */
//	public void destroy(){
//		defaultMQPushConsumer.shutdown();
//	}
//
//	/**获取DefaultMQProducer
//	 * */
//	public DefaultMQPushConsumer getDefaultMQPushConsumer(){
//		return defaultMQPushConsumer;
//	}
//
//	/**setter method
//	 * */
//	public void setNamesrvAddr(String namesrvAddr) {
//		this.namesrvAddr = namesrvAddr;
//	}
//
//	public void setConsumerGroup(String consumerGroup) {
//		this.consumerGroup = consumerGroup;
//	}
//
//}
